package com.juneyao.log.logcenter.scheduler.mapping;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author quanbiao
 * @date 2018-07-31
 * 操作日志和应用日志mapping
 */
public final class IndexMapping {

    public static final Map<String, Map<String, Map>> operateIndexMapping = new LinkedHashMap<>();

    public static final Map<String, Map<String, Map>> applicationIndexMapping = new LinkedHashMap<>();

    static {
        //字段类型为keyword，不分词
        Map<String, String> keyWordType = new LinkedHashMap<>();
        keyWordType.put("type", "keyword");
        //object type
        Map<String, String> objectType = new LinkedHashMap<>();
        objectType.put("type", "object");
        // int type
        Map<String, String> intType = new LinkedHashMap<>();
        intType.put("type", "integer");
        //date type
        Map<String, String> dateType = new LinkedHashMap<>();
        dateType.put("type", "date");
        dateType.put("format", "yyyy-MM-dd HH:mm:ss.SSS");

        //操作日志字段
        Map<String, Map> innerMapOpera = new LinkedHashMap<>();
        innerMapOpera.put("service_name", keyWordType);
        innerMapOpera.put("user_name", keyWordType);
        innerMapOpera.put("full_name", keyWordType);
        innerMapOpera.put("title", keyWordType);
        innerMapOpera.put("type", keyWordType);
        innerMapOpera.put("user_agent", keyWordType);
        innerMapOpera.put("request_uri", keyWordType);
        innerMapOpera.put("method_name", keyWordType);
        innerMapOpera.put("method", keyWordType);
        innerMapOpera.put("params", objectType);
        innerMapOpera.put("result", keyWordType);
        innerMapOpera.put("time", intType);
        innerMapOpera.put("ip", keyWordType);
        innerMapOpera.put("ip_detail", keyWordType);
        innerMapOpera.put("exception", keyWordType);
        innerMapOpera.put("request_time", dateType);
        innerMapOpera.put("response_time", dateType);
        innerMapOpera.put("trace_Id", keyWordType);
        innerMapOpera.put("jwt_token", keyWordType);
        innerMapOpera.put("refer", keyWordType);
        innerMapOpera.put("cookie", keyWordType);
        innerMapOpera.put("system_type", keyWordType);
        operateIndexMapping.put("properties", innerMapOpera);

        //应用日志字段
        Map<String, Map> innerMapApp = new LinkedHashMap<>();
        innerMapApp.put("service_name", keyWordType);
        innerMapApp.put("timestamp", dateType);
        innerMapApp.put("thread", keyWordType);
        innerMapApp.put("log_level", keyWordType);
        innerMapApp.put("class_name", keyWordType);
        innerMapApp.put("line_number", keyWordType);
        innerMapApp.put("message", keyWordType);
        innerMapApp.put("stack_trace", keyWordType);
        applicationIndexMapping.put("properties", innerMapApp);
    }
}
